package ch.sfug.anim.tween.color {
	import ch.sfug.events.TweenEvent;	
	
	import flash.display.DisplayObject;
	
	import ch.sfug.anim.tween.CompositeTween;
	import ch.sfug.anim.tween.property.PropertyTween;
	import ch.sfug.util.RGB;	

	/**
	 * @author Administrator
	 */
	public class AbstractColorTween extends CompositeTween {


		public function AbstractColorTween( d:Number ) {
			super();
			tween = new PropertyTween( new RGB(), d );
			tween.addEventListener( TweenEvent.TWEEN_UPDATE, applyColor);
		}
		
		private function applyColor( event:TweenEvent ):void {
			apply( color );
		}

		/**
		 * overwrite this class to return the start color value of the color tweened target
		 */
		protected function getStartColor():RGB {
			// ABSTRACT
			return new RGB();
		}
		
		
		public function apply( rgb:RGB ):void {
			//ABSTRACT
		}
		
		
		public function tweenColorTo( end:RGB, ease:Function = null ):void {
			var start:RGB = getStartColor();
			PropertyTween( tween ).tween( { red:{ from:start.red, to:end.red, easing:ease }, green:{ from:start.green, to:end.green, easing:ease }, blue:{ from:start.blue, to:end.blue, easing:ease } } );
		}
		
		public function tweenColorFromTo( start:RGB, end:RGB, ease:Function ):void {
			PropertyTween( tween ).tween( { red:{ from:start.red, to:end.red, easing:ease }, green:{ from:start.green, to:end.green, easing:ease }, blue:{ from:start.blue, to:end.blue, easing:ease } } );
		}
		
		
		public function get color():RGB {
			return RGB( PropertyTween( tween ).target );
		}
	}
}
